package com.smart.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.smart.dao.BaseDao;
import com.smart.dao.MessageDao;
import com.smart.dao.Page;
import com.smart.dao.PageRequest;
import com.smart.model.Message;
import com.smart.model.MessageCond;

/**
 * 
 * @author Sunxin
 *
 */
 
@Service
public class MessageServiceImpl extends BaseEntityService<Message, MessageCond, Long> implements MessageService{

	@Autowired
	private MessageDao dao;
	
	@Override
	protected BaseDao<Message, MessageCond, Long> getDao() {
		return dao;
	}

	@Override
	public List<Message> getMessages(Long currentId) {
		if(currentId<0) {
			PageRequest pageRequest = new PageRequest();
			pageRequest.setPageNumber(50);
			
			MessageCond cond = new MessageCond();
			cond.addOrderByDesc("id");
			Page<Message> page = dao.findPage(pageRequest, cond);
			return page.getContent();
		}
		else {
			PageRequest pageRequest = new PageRequest();
			pageRequest.setPageNumber(50);
			
			MessageCond cond = new MessageCond();
			cond.addOrderByDesc("id");
			cond.setIdGt(currentId);
			Page<Message> page = dao.findPage(pageRequest, cond);
			return page.getContent();
		}
	}
	
	
}
